/**
 * @Author：ming
 * @Date：2023/10/5 1:04 AM
 * @Filename：Lc43
 */

/**
 * @author ming
 */
public class Lc43 {
    public String multiply(String num1, String num2) {


        int len1 = num1.length()-1;
        int len2 = num2.length()-1;

        if(len1==0&&num1.charAt(0)=='0'){
            return "0";
        }else if(len2==0&&num2.charAt(0)=='0'){
            return "0";
        }
        String muti = new String();
        while (len1>=0){
            int x = num1.charAt(len1)-48;
            StringBuilder temp = new StringBuilder();
            String s = mutiOne(x,num2);
            temp.append(s);
            for (int i = num1.length()-1; i >len1 ; i--) {
                temp.append('0');
            }
            muti = addAll(muti,temp.toString());

            len1--;
        }
        return muti;
    }

    //字符串加法

    public String addAll(String n1,String n2){

        int len1 = n1.length()-1;
        int len2 =n2.length()-1;
        int res =0;
        int sum = 0;
        StringBuilder sb = new StringBuilder();
        while (len1>=0||len2>=0){
            int x = len1<0?0:n1.charAt(len1)-48;
            int y = len2<0?0:n2.charAt(len2)-48;

            sum = (x+y+res)%10;
            res =(x+y+res)/10;
            sb.append(sum);
            len1--;
            len2--;
        }
        if(res>0){
            sb.append(res);
        }

        return sb.reverse().toString();
    }

    public String mutiOne(int n,String s){
        if(n==0){
            return "0";
        }
        int len = s.length()-1;
        int res =0;
        StringBuilder sb = new StringBuilder();
        while (len>=0){
            int x = s.charAt(len)-48;
            int sum = (x*n+res)%10;
             res = (x*n+res)/10;
             sb.append(sum);
             len--;
        }
        if(res>0){
            sb.append(res);
        }
        return sb.reverse().toString();
    }
}
